public class DeleteDuplicatesInList {
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null) return head;
        ListNode next = head.next;
        int val = head.val;
        if (next.val == val) {
            ListNode temp = head.next;
            while (temp != null && temp.val == val) {
                temp = temp.next;
            }
            head = deleteDuplicates(temp);
        } else {
            head.next = deleteDuplicates(next);
        }
        return head;

    }
}
